package com.dzsw.javabase.array;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class ListCloneDemo {


    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("a000");
        list.add("a001");
        list.add("a002");
        list.add("a003");
        list.add("a004");
        list.add("a005");
        list.add("a006");
        list.add("a007");
        list.add("a008");
        list.add("a009");

//        List<String> clone1List = clone1(list);
//        List<String> clone2List = clone2(list);
//        List<String> clone3List = clone3(list);
//        clone1List.removeFirst();
//        clone2List.removeLast();
//        clone3List.remove(3);
//        System.out.println("list >> " + CollUtil.join(list, ","));
//        System.out.println("clone1 >> " + CollUtil.join(clone1List, ","));
//        System.out.println("clone2 >> " + CollUtil.join(clone2List, ","));
//        System.out.println("clone3 >> " + CollUtil.join(clone3List, ","));
    }

    public static <T> List<T> clone1(List<T> list) {
        return new ArrayList<>(list);
    }


    public static <T> List<T> clone2(List<T> list) {
        List<T> newList = new ArrayList<>(list.size());
        newList.addAll(list);
        return newList;
    }


    public static <T> List<T> clone3(List<T> list) {
        return list.stream().collect(Collectors.toList());
    }

}
